import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class FilmDetailsFrame extends JFrame{
    JLabel details;
    Browser poster;
    LinkedList<String> timeList;
    ArrayList<JButton> bookTicket = new ArrayList();
    ArrayList<String> times = new ArrayList();
    BrowserButton panel;
    int xPos = 10;
    int yPos = 450;
    String filmImage;
    JButton timeButton;

    FilmDetailsFrame( String hyperlink, String filmDetails ){
        Image bGround = ReadImage.getImage("http://wallpapers.wallbase.cc/rozne/wallpaper-389121.jpg");
        Browser bGPanel = new Browser( bGround );
        add(bGPanel);
        setVisible(true);
        setSize(750,750);

        filmImage = hyperlink;

        poster = new Browser( ReadImage.getImage( hyperlink ) );
        details = new JLabel( filmDetails );

        timeList = Film.getFilmTimes( hyperlink );

        for( String time : timeList ){
            timeButton = new JButton( time );
            bookTicket.add( timeButton );
            times.add( time );
            timeButton.setBounds(xPos, yPos, 200, 200);
            bGPanel.add( timeButton );
            xPos = xPos + 50;
        }

        for(int i=0; i<bookTicket.size(); i++){
            bookTicket.get(i).setActionCommand( times.get(i) );
            bookTicket.get(i).addActionListener(new ActionListener(){
                public void actionPerformed( ActionEvent ae ){
                    if( ImageInJFrame.loggedIn == true){
                        ChooseSeatsFrame chooseSeats = new ChooseSeatsFrame( filmImage,1,1 );
                    }else{
                        JOptionPane.showMessageDialog( null,"Please Log in to book tickets" );
                    }
                }
            });
        }

        poster.setBounds(10,20,130,200);
        details.setBounds(200,20,250,400);

        bGPanel.add( poster );
        bGPanel.add( details );
    }

}

